package frobagroup.controller.backstage;

import frobagroup.entities.backstage.Feedback;
import frobagroup.pagination.Pagination;
import frobagroup.services.backstage.FeedbackService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Tinsley on 2018/6/19.
 */
@RequestMapping("/webAPI/feedback")
@RestController
public class FeedbackController {


    @Autowired
    private FeedbackService feedbackService;


    @RequestMapping(value = "/findFeedbacks", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findOwnFeedback(HttpServletRequest request,
                                                                 @RequestBody Pagination pagination) throws Exception{
        return ResponseModel.success(feedbackService.findFeedbacks(pagination,(String)request.getAttribute("id")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/addFeedback", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> addFeedback(HttpServletRequest request,
                                                             @RequestBody Feedback feedback) throws Exception{
        return ResponseModel.success(feedbackService.addFeedback(feedback,(String)request.getAttribute("id")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/replyFeedback", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> replyFeedback(HttpServletRequest request,
                                                             @RequestBody Feedback feedback) throws Exception{
        return ResponseModel.success(feedbackService.replyFeedback(feedback,(String)request.getAttribute("staffId")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/feedbackDetail/{fbId}", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> feedbackDetail(HttpServletRequest request,
                                                                @PathVariable String fbId) throws Exception{
        return ResponseModel.success(feedbackService.feedbackDetail(fbId),
                Constants.RESPONSE_STATUS_SUCESS);
    }


}
